package gameLogic;
import java.util.ArrayList;
import java.util.Random;
import java.util.Date;

abstract class Strategy implements Comparable<Strategy> {
	protected Board b;
	protected BoardState side;
	protected Observer ob;
	protected static Random randGen = new Random((new Date().getTime()));
	
	public Strategy(Board b, BoardState s, Observer ob) {
		this.b = b;
		this.side = s;
		this.ob = ob;
	}
	public abstract Move[] getAllMove();
	public Move getMove() {
		Move[] allMoves = getAllMove();
		if(allMoves == null || allMoves.length == 0)
			return null;
		else if(allMoves.length == 1)
			return allMoves[0];
		else
			return allMoves[randGen.nextInt(allMoves.length)];
	}
	
	protected abstract int getPriority();
	public int compareTo(Strategy s) {
		if(this.getPriority() > s.getPriority())
			return 1;
		else if(this.getPriority() == s.getPriority())
			return 0;
		else
			return -1;
	}
	protected ArrayList<Move> getAllAllowed() {
		ArrayList<Move> allMove = new ArrayList<Move>();
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				if(b.isEmpty(i, j))
					allMove.add(new Move(i,j,side));
		return allMove;
	}
}
